UTimer = {}
local uniqueId = 0
local callList = {}
local tempCallList = {}
local traceback = __G__TRACKBACK__ or traceback
local function GetUniqueId()
    uniqueId = uniqueId + 1
    return uniqueId
end
--delay 秒
function UTimer.DelayCall(callback,tb,delaySecond)
    local id = GetUniqueId()
    delaySecond = delaySecond or 0
    tempCallList[id] = {tb = tb,callback = callback,interval = delaySecond,curTime = delaySecond,times = 1}
    return id
end
function UTimer.FrameCall(callback,tb,times)
    local id = GetUniqueId()
    if times < 0 then times = -1 end
    tempCallList[id] = {tb = tb,callback = callback,times = times,isFrame = true,curTime = 0}
    return id
end
--interval 秒
function UTimer.TimeCall(callback,tb,interval,times)
    local id = GetUniqueId()
    interval = interval or 0
    if not times or times < 0 then times = -1 end
    tempCallList[id] = {tb = tb,callback = callback,times = times,interval = interval,curTime = interval}
    return id
end
function UTimer.Remove(id)
    if id == nil then return end
    callList[id] = nil
    tempCallList[id] = nil
end
function UTimer.RemoveAll()
    for k,v in pairs(callList) do
        callList[k] = nil
    end
    for k,v in pairs(tempCallList) do
        tempCallList[k] = nil
    end
end
local function loop()
    for k,v in pairs(tempCallList) do
        callList[k] = v
        tempCallList[k] = nil
    end
    for k,v in pairs(callList) do
        if v.isFrame then
            if v.times == -1 or v.times > 0 then
                local flag, msg = xpcall(v.callback, traceback,v.tb)
                if v.times > 0 then
                    v.times = v.times -1
                end
            end
        else
            v.curTime = v.curTime - Time.deltaTime
            if v.times == -1 or v.times > 0 and v.curTime <= 0 then
                local flag, msg = xpcall(v.callback, traceback,v.tb)
                if v.times > 0 then
                    v.times = v.times - 1
                end
                v.curTime = v.curTime + v.interval
            end
        end
        if v.times == 0 then
            callList[k] = nil
        end
    end
end
---@type UpdateComponent
local c = panelMgr.gameObject:AddComponent(typeof(UpdateComponent))
c.updateCallback = loop
--UpdateBeat:Add(loop)
